package com.example.workroom.controller;

import com.example.workroom.dto.PeoplePageQueryDTO;
import com.example.workroom.pojo.People;
import com.example.workroom.result.PageResult;
import com.example.workroom.result.Result;
import com.example.workroom.service.PeopleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.websocket.server.PathParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/people")
@Api(tags = "人员管理")
public class PeopleController {
    @Autowired
    private PeopleService peopleService;

    /**
     * 新增成员
     * @param people
     * @return
     */
    @PostMapping
    @ApiOperation("新增成员")
    public Result<String> save(@RequestBody People people){
        log.info("新增成员：{}", people);
        peopleService.save(people);
        return Result.success();
    }

    /**
     * 分页查询
     * @param peoplePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(PeoplePageQueryDTO peoplePageQueryDTO){
        log.info("分页查询：{}", peoplePageQueryDTO);
        PageResult pageResult = peopleService.pageQuery(peoplePageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 批量删除员工数据
     * @param
     * @return
     */
    @DeleteMapping("/{ids}")
    @ApiOperation("批量删除成员")
    public Result<String> deleteIds(@PathVariable List<Integer> ids){
        log.info("批量删除员工数据：{}", ids);
        peopleService.deleteIds(ids);
        return Result.success();
    }

    /**
     * 根据id查询员工
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询员工")
    public Result<People> getById(@PathVariable Integer id){
        log.info("根据id查询员工：{}", id);
        People people = peopleService.getById(id);
        return Result.success(people);
    }

    /**
     * 根据id修改员工信息
     * @param people
     * @return
     */
    @PutMapping
    @ApiOperation("根据id修改员工信息")
    public Result<String> update(@RequestBody People people){
        log.info("根据id修改员工信息：{}", people);
        peopleService.update(people);
        return Result.success();
    }



}
